package com.wedo.mall.fragment;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.e.library.fragment.EFragment;
import com.e.library.http.EApi;
import com.e.library.utils.EViewUtils;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.wedo.mall.R;
import com.wedo.mall.WApp;
import com.wedo.mall.activity.user.MyCollectionActivity;
import com.wedo.mall.adapter.AgentAdapter;
import com.wedo.mall.entity.Agent;
import com.wedo.mall.entity.Order;
import com.wedo.mall.ptr.Pull2Refresh;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class CollectionShopFragment extends EFragment<MyCollectionActivity> {

    //@BindView(R.id.rv_shop) RecyclerView rv_shop;
    @BindView(R.id.tv_empty) TextView tv_empty;
    @BindView(R.id.rv_list) XRecyclerView rv_list;
    //private AgentAdapter mShopAdapter;

    private AgentAdapter adapter;

    private Pull2Refresh<Agent> ptr;

    public static CollectionShopFragment with(){
        return new CollectionShopFragment();
    }

    @Override
    protected int layout() {
        return R.layout.fragment_collection_shop;
    }

    @Override
    protected void onFragmentCreated(View contentView, Bundle bundle) {
/*        rv_shop.setHasFixedSize(true);
        mShopAdapter = AgentAdapter.search(this.getActivity(),shops());
        EViewUtils.vertical(rv_shop);
        rv_shop.setAdapter(mShopAdapter);*/

        rv_list.setHasFixedSize(true);
        EViewUtils.vertical(rv_list);
        ptr = new Pull2Refresh<>();

        adapter = AgentAdapter.search(getContext(),null);
        adapter.isCollection(true);
        adapter.setOnRefreshClickListener(new AgentAdapter.OnCollectionShopsFragmentListener() {
            @Override
            public void onRefreshClick() {
                refresh();
            }
        });

        adapter.collectionShoplistener(activity());
        ptr.widget(rv_list).adapter(adapter).url(EApi.USER_COLLECTSHOPS).params(WApp.lngLat()).clazz(Agent.class).emptyWidget(tv_empty).done();
    }

    public void refresh(){
        ptr.refresh();
    }

}
